@extends('layouts.app', ['activePage' => 'video', 'titlePage' => '视频课程管理'])

@section('content')
  <div class="content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-12">
          <form method="post" action="{{ route('video.update', $video) }}" autocomplete="off" class="form-horizontal"
                enctype="multipart/form-data">
            @csrf
            @method('put')

            <div class="card ">
              <div class="card-header card-header-primary">
                <h4 class="card-title">编辑</h4>
                <p class="card-category"></p>
              </div>
              <div class="card-body ">
                <div class="row">
                  <div class="col-md-12 text-right">
                    <a href="{{ route('video.index') }}" class="btn btn-sm btn-primary">返回列表</a>
                  </div>
                </div>
                <div class="row">
                  <label class="col-sm-2 col-form-label">标题</label>
                  <div class="col-sm-7">
                    <div class="form-group{{ $errors->has('title') ? ' has-danger' : '' }}">
                      <input class="form-control{{ $errors->has('title') ? ' is-invalid' : '' }}" name="title"
                             id="input-title" type="text" placeholder="标题" value="{{ old('title', $video->title) }}"
                             required/>
                      @if ($errors->has('title'))
                        <span id="title-error" class="error text-danger"
                              for="input-title">{{ $errors->first('title') }}</span>
                      @endif
                    </div>
                  </div>
                </div>
                <div class="row">
                  <label class="col-sm-2 col-form-label">介绍</label>
                  <div class="col-sm-7">
                    <div class="form-group{{ $errors->has('intro') ? ' has-danger' : '' }}">
                      <textarea class="form-control{{ $errors->has('intro') ? ' is-invalid' : '' }}" name="intro"
                                id="input-title" type="text" placeholder="视频课程介绍"
                                required rows="8">{{ old('intro', $video->intro) }}</textarea>
                      @if ($errors->has('intro'))
                        <span id="intro-error" class="error text-danger"
                              for="input-intro">{{ $errors->first('intro') }}</span>
                      @endif
                    </div>
                  </div>
                </div>
                <div class="row">
                  <label class="col-sm-2 col-form-label">价格</label>
                  <div class="col-sm-7">
                    <div class="form-group{{ $errors->has('price') ? ' has-danger' : '' }}">
                      <input class="form-control{{ $errors->has('price') ? ' is-invalid' : '' }}" name="price"
                             id="input-price" type="text" placeholder="设置课程价格" value="{{ old('price', $video->price) }}"
                             required
                             onkeyup="if(isNaN(value))execCommand('undo');else value=value.replace(/^(\d+)\.(\d\d).*$/,'$1.$2')"
                             onafterpaste="if(isNaN(value))execCommand('undo');else value=value.replace(/^(\d+)\.(\d\d).*$/,'$1.$2')"
                      />
                      @if ($errors->has('price'))
                        <span id="price-error" class="error text-danger"
                              for="input-price">{{ $errors->first('price') }}</span>
                      @endif
                    </div>
                  </div>
                </div>
                <div class="row">
                  <label class="col-sm-2 col-form-label">视频</label>
                  <div class="col-sm-7">
                    @foreach($video->videos as $v)
                      <div class="form-check">
                        <label class="form-check-label">
                          <input class="form-check-input" type="checkbox" name="oldVideos[]" value="{{ $loop->index }}"
                                 @if($v->active)
                                 checked
                            @endif >
                          {{ $v->videoName }}
                          <span class="form-check-sign"><span class="check"></span></span>
                        </label>
                      </div>
                    @endforeach
                    <div class="form-group{{ $errors->has('videos') ? ' has-danger' : '' }}">
                      <div class="fileinput fileinput-new" data-name="videoFiles[]" data-max-size="100"
                           data-provides="fileinput">
                        <span class="btn btn-raised btn-round btn-file">
                          <span class="fileinput-new">添加文件</span>
                          <span class="fileinput-exists">修改</span>
                          <input type="file" accept="video/x-msvideo, video/mp4" multiple>
                        </span>
                        <span class="fileinput-filename"></span>
                        <a href="#" class="close fileinput-exists" data-dismiss="fileinput"
                           style="float: none">&times;</a>
                      </div>
                      @if ($errors->has('videos'))
                        <span id="video-error" class="error text-danger"
                              for="input-video">{{ $errors->first('video') }}</span>
                      @endif
                    </div>
                  </div>
                </div>
              </div>
              <div class="card-footer justify-content-end">
                <button type="submit" class="btn btn-rose">保存</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
@endsection
@push("js")
  <script>
    $('.fileinput').on('max_size.bs.fileinput', function () {
      alert("选择的文件过大，单个文件不得超过100M");
    });
  </script>
@endpush
